package demo.nacos.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {

    @Value("${useLocalCache:false}")
    private boolean useLocalCache;

    private static int iCount = 1;
    private static int jCount = 1;

    public ConfigController() {
        //每次配置变化，bean都会重新实例化
        System.out.println("实例化" + iCount++ + "次");
    }

    @PostConstruct
    public void init() {
        //每次配置变化，bean都会重新初始化
        System.out.println("初始化" + jCount++ + "次");
    }

    @RequestMapping("/get")
    public boolean get() {
        return useLocalCache;
    }
}
